/**
 * 期约连锁
 */
;(function () {
    let p = new Promise((resolve, reject) => {
        console.log('first')
        resolve()
    })
    p.then(() => console.log('second'))
        .then(() => console.log('third'))
        .then(() => console.log('fourth'))

    //要真正执行异步任务，可以改写前面的例子，让每个执行器都返回一个期约实例。这样就可以让每个后续期约都等待之前的期约，也就是串行化异步任务。
    let p1 = new Promise((resolve, reject) => {
        console.log('p1 executor')
        setTimeout(resolve, 1000)
    })
    p1.then(() => new Promise((resolve, reject) => {
        console.log('p2 executor')
        setTimeout(resolve, 1000)
    }))
        .then(() => new Promise((resolve, reject) => {
            console.log('p3 executor')
            setTimeout(resolve, 1000)
        }))
        .then(() => new Promise((resolve, reject) => {
            console.log('p4 executor')
            setTimeout(resolve, 1000)
        }))


})()